package cc.plumgo.ss.yo.entity;

import cc.plumgo.ss.core.Constants;

public class FlyBook extends Enemy {
	public static final int ENM_FLY_UP = 0;
	public static final int ENM_FLY_DOWN = 1;
	public static final int ENM_FLY_TYPE_NUM = 2;
	private int flowDirect = ENM_FLY_UP;

	public FlyBook(int x, int y) {
		super(EnemyFactory.ENM_FLYBOOK, x, y);
	}

	public void logic() {
		super.logic();
		switch (state) {
		case ENM_WALK: {
			updateDirectY();
			break;
		}
		}
		
		updateSpriteDirect(state, spriteDir);
		updateAllPositions();
	}

	public void updateDirectY() {
		int tmpY = initPosY;
		switch (flowDirect) {
		case ENM_FLY_UP: {
			tmpY = posY + walkSpeed;
			if (tmpY > initPosY + Constants.ENM_WALK_RANGE_Y) {
				setFlowDirect(ENM_FLY_DOWN);
			}
			break;
		}
		case ENM_FLY_DOWN: {
			tmpY = posY - walkSpeed;
			if (tmpY < initPosY - Constants.ENM_WALK_RANGE_Y) {
				setFlowDirect(ENM_FLY_UP);
			}
			break;
		}
		}
		posY = tmpY;
	}

	public void setFlowDirect(int flowDirect) {
		if (flowDirect < 0 || flowDirect >= ENM_FLY_TYPE_NUM) {
			return;
		}
		this.flowDirect = flowDirect;
	}
}
